//using System;
//using System.Collections;
//using System.ComponentModel;
//using System.Drawing;
//using System.Data;
//using System.Windows.Forms;
//using CStock;
//using System.Diagnostics;
//using CapitalReSources;


//namespace CGrid
//{
//    /// <summary>
//    /// Summary description for GridIntraday.
//    /// </summary>
//    public class GridIntraday : GridBase, IGridIntraday
//    {



//        //private IPortfolio portfolio;
//        protected IMainClass mainClass;
		
//        private System.Windows.Forms.Timer timerSaveQuotes;
		
//        Random randomData;

//        public GridIntraday():base()
//        {
//            this.mainClass = MainClass.Instance;
//            // This call is required by the Windows.Forms Form Designer.
//            InitializeComponent();
//            randomData = new Random(unchecked((int)DateTime.Now.Ticks)); 

//            try
//            {
//                this.mainClass = MainClass.Instance;
//                this.mainClass.GridIntraday = this;
//            }
//            catch
//            {
//                //this occurs in design mode - do nothing
//            }
			
//        }

//        /// <summary> 
//        /// Clean up any resources being used.
//        /// </summary>
//        protected override void Dispose( bool disposing )
//        {
			
//            base.Dispose( disposing );
//        }

//        #region Component Designer generated code
//        /// <summary> 
//        /// Required method for Designer support - do not modify 
//        /// the contents of this method with the code editor.
//        /// </summary>
//        private void InitializeComponent()
//        {
//            this.timerSaveQuotes = new System.Windows.Forms.Timer();
			
//            this.timerSaveQuotes.Interval = 10000;
//            //this.timerSaveQuotes.Tick += new System.EventHandler(this.timerSaveQuotes_Tick);
			

//        }
//        #endregion

//        #region Grid creation

	
//        public bool FillPortfolioGrid(IPortfolio port)
//        {
//            if(this.grid1.Rows.Count < 1)
//            {
//                Debug.Assert(false,"Software error : the grid was not correctly created");
//                return false;
//            }
//            for(int i = 0; i < port.DataItems.Count; i++)
//            {
//                IDataItem di = port.DataItems[i];
//                di.QuoteWeb = new QuoteWeb();

//                IDataClass dc = port.DataItems[i].DataClass;
//                //dc.GetConfiguredIntradayData(this.programContext.Configuration.Dates.DateIntraday);
				


//                this.AddRow_Single(dc);
//            }
//            return true;
		
			

			
//        }
	
//        #endregion

//        #region add grid line

////		public void AddRow(IDataClass dc)
////		{
////			grid1.Rows ++;
////			int rowListCount = grid1.Rows -1;
////		
////			
////
////			SourceGrid2.Cell c;
////			for(int i = 0; i < cellDataModel.GetLength(0); i++)
////			{
////				c = new SourceGrid2.Cell();
////				grid1[rowListCount,i] = c;
////				grid1[rowListCount,i].Model = cellDataModel[i];
////				grid1[rowListCount,i].VisualProperties = visualProp;
////			}				
////
////			c = grid1[rowListCount,0];
////			c.Value = dc.Name;
////
////			c= grid1[rowListCount,1];
////			c.Value = dc.Symbol;
////
////			c= grid1[rowListCount,2];
////			c.Value = dc.WKN;
////
////			c= grid1[rowListCount,3];
//////			c.Value = dc.WKN;
////
////
////			c= grid1[rowListCount,4];
////			c.Value = DateTime.Now.ToShortTimeString();
////
////
////
////			//rowListCount++;
////			
////			
////		}
////		private void AddDummyRow()
////		{
////			grid1.Rows ++;
////			int rowListCount = grid1.Rows -1;
////
////			System.IO.StreamReader streamReader = new System.IO.StreamReader(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("ClientC.WinbisGrid.xml"));
////			System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
////			xmlDoc.LoadXml(streamReader.ReadToEnd());
////			streamReader.Close();
////			System.Xml.XmlNodeList rowList = xmlDoc.SelectNodes("//row");
////
////
////			foreach(System.Xml.XmlNode node in rowList)
////			{
////				for(int i = 0; i < cellDataModel.GetLength(0); i++)
////				{
////					SourceGrid2.Cell c = new SourceGrid2.Cell(node.Attributes[i].InnerText);
////					grid1[rowListCount,i] = c;
////					grid1[rowListCount,i].Model = cellDataModel[i];
////					grid1[rowListCount,i].VisualProperties = visualProp;
////				}
////				
////					
////
////				rowListCount++;
////			}
////		}
//        public void AddRow(IQuoteWeb webq)
//        {
			
//        }
	
//        public void AddRow()
//        {
			
////			//System.Diagnostics.Debug.WriteLine(shareWKN + ";" + last + ";" + ask + ";");
////			grid1.Rows = grid1.Rows + 1;
////			int rowListCount = grid1.Rows -1;
////			
////
////			for(int i = 0; i < cellDataModel.GetLength(0); i++)
////			{
////				SourceGrid2.Cell c = new SourceGrid2.Cell();
////				grid1[rowListCount,i] = c;
////				
////				grid1[rowListCount,i].Model = cellDataModel[i];
////				grid1[rowListCount,i].VisualProperties = visualProp;
////			}
////
////			grid1[1,3].BackColor = System.Drawing.Color.Red;

			

//            //this.AddRow_Single(
		

//        }

//        #endregion

//        #region TWS

//        //public void OnTick(object sender, TickEventArgs e)
//        //{
//        //    //string str = sender.Name;
//        //    int wkn = e.WKN;
//        //    IDataItem dcFound = null;
//        //    int indexFound = 0;
//        //    for(int i = 0; i < this.portfolio.DataItems.Count; i++)
//        //    {
//        //        IDataItem di = this.portfolio.DataItems[i];
//        //        IDataClass dc = this.portfolio.DataItems[i].DataClass;
//        //        if(di.WKN == wkn)
//        //        {
//        //            indexFound = i;
//        //            dcFound = di;
//        //            break;
//        //        }
//        //    }

//        //    if(dcFound != null)
//        //    {
//        //        //System.Diagnostics.Debug.WriteLine(wkn + "; " + e.TickType.ToString() + " ; "  + e.Val.ToString());
//        //    }
//        //    else
//        //    {
//        //        //the data class may be in some other instance of this grid (other form)
//        //        return;
//        //        //System.Diagnostics.Debug.Assert(false,"Error getting intraday quotes: " + wkn);
//        //    }
//        //    //grid1[indexFound + 1 ,e.TickType].Value = e.Val;

//        //    grid1[indexFound + 1 ,4].Value = DateTime.Now.ToLongTimeString();
//        //    switch (e.TickType)
//        //    {
//        //        case 0 : //bid size
//        //        {
//        //            //grid1[indexFound + 1 ,7].Value = e.Val;
//        //            SetCellValueWithColor(indexFound +1,7,e.Val);
//        //            dcFound.QuoteWeb.BidSize =Convert.ToInt32( e.Val);
//        //            break;
//        //        }
//        //        case 1 : //bid price
//        //        {
//        //            //grid1[indexFound + 1 ,6].Value = e.Val;
//        //            SetCellValueWithColor(indexFound +1,6,e.Val);
//        //            dcFound.QuoteWeb.Bid = Convert.ToDouble(e.Val);
//        //            break;
//        //        }
//        //        case 2 : //ask price
//        //        {
//        //            //grid1[indexFound + 1 ,8].Value = e.Val;
//        //            SetCellValueWithColor(indexFound +1,8,e.Val);
//        //            dcFound.QuoteWeb.Ask =Convert.ToDouble(e.Val);
//        //            break;
//        //        }
//        //        case 3 : //ask volume
//        //        {
//        //            //grid1[indexFound + 1 ,9].Value = e.Val;
//        //            SetCellValueWithColor(indexFound +1,9,e.Val);
//        //            dcFound.QuoteWeb.AskSize = Convert.ToInt32(e.Val);
//        //            break;
//        //        }
//        //        case 4 : //last price
//        //        {
//        //            //grid1[indexFound + 1 ,3].Value = e.Val;
//        //            SetCellValueWithColor(indexFound +1,3,e.Val);
//        //            double fVal =  Convert.ToDouble(e.Val);
//        //            if(fVal != 0F)
//        //            {

//        //                dcFound.QuoteWeb.DATE = DateTime.Now;
//        //                dcFound.QuoteWeb.LastPrice = Convert.ToDouble(e.Val);

//        //                dcFound.DataClass.QuoteCollection.Add(dcFound.QuoteWeb);
//        //                MainClass.Instance.RefreshIntradayChart(dcFound.DataClass);

//        //                dcFound.QuoteWeb = new QuoteWeb();
//        //            }
//        //            //create new quote
//        //            break;
//        //        }
//        //        case 5 : //last size
//        //        {
//        //            SetCellValueWithColor(indexFound +1,5,e.Val);
//        //            //grid1[indexFound + 1 ,5].Value = e.Val;
//        //            dcFound.QuoteWeb.LAST_SIZE =Convert.ToInt32(e.Val);
//        //            break;
//        //        }
//        //        case 7 : //close 
//        //        {
//        //            //SetCellValueWithColor(indexFound +1,8,e.Val);
//        //            //grid1[indexFound + 1 ,1].Value = e.Val;
//        //            //dcFound.QuoteWeb.LAST_SIZE = e.Val;
//        //            break;
//        //        }
//        //        case 8 : //close volume
//        //        {
//        //            //grid1[indexFound + 1 ,0].Value = e.Val;
//        //            break;
//        //        }
			
//        //        default:
//        //        {
//        //            return ;
					
//        //        }

           

//        //    }
//            //switch

////			//for(
////			switch (message)
////			{
////				case ("Complete"):
////				{
////					break;
////				}
////			}
////			Contract c = e.NewValue as Contract;
//            //IPortfolio port = sender as IPortfolio;
////		}
//        public void OnTickComplete(object sender, CUtil.TickEventArgs e)
//        {
////			//string str = sender.Name;
////			string message = e.PropertyName;
////			switch (message)
////			{
////				case ("Complete"):
////				{
////					break;
////				}
////			}
////			Contract c = e.NewValue as Contract;
//            //IPortfolio port = sender as IPortfolio;
//        }
	
//        #endregion

//        private void SetDummyData(IDataClass dc)
//        {
//            //System.Collections.ArrayList quoteCollection = dc.QuoteCollection;
//            IListQuotes quoteCollection = dc.QuoteCollection;

//            QuoteWeb qw = new QuoteWeb();
//            qw.DATE = DateTime.Now;
			
//            //randomData.NextDouble();

//            double f = (0.5F - (double)randomData.NextDouble());

//            qw.LastPrice = dc.SeriesOpen[dc.SeriesOpen.Count -1] + f * dc.SeriesOpen[dc.SeriesOpen.Count -1] /50F ;

//            quoteCollection.Add((IQuote)qw);
//            MainClass.Instance.RefreshIntradayChart(dc);
			
//        }
////        private void timerSaveQuotes_Tick(object sender, System.EventArgs e)
////        {
////            this.timerSaveQuotes.Interval = this.programContext.Configuration.IntradayDataSaveInterval * 1000;

////            for(int i = 0; i < this.portfolio.DataItems.Count; i++)
////            {
////                IDataClass dc = portfolio.DataItems[i].DataClass;
//////				string path = this.programContext.Configuration.Directories.IntradayPath + "\\" + dc.ID;
//////				if(! System.IO.Directory.Exists(path))
//////				{
//////					System.IO.Directory.CreateDirectory(path);
//////				}

////                //dummy data:
////                //SetDummyData(dc);
////                //timerSaveQuotes.Stop();
////                dc.Serialize();


////                //AddRow(dc);
////            }
////            //for(in
////        }

//    }
//}
